package com.abner.springcloud.consumer.movie.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * @author xijing.jiang
 */
@RestController
@Slf4j
public class UploadController {

    @PostMapping(value = "/upload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadFile(@RequestPart("file") MultipartFile file){
        log.info("start upload File ：【{}】",file.getOriginalFilename());
        try {
            file.transferTo(new File("D:\\upload_1.txt"));
            log.info("success to upload File ：【{}】",file.getOriginalFilename());
        } catch (IOException e) {
            log.error("exception to upload File : [{}], error is : [{}]",file.getOriginalFilename(),e);
        }
        return "success";
    }
}
